package com.thinkwide.data.servlet;

import com.thinkwide.data.core.MFPath;
import com.thinkwide.data.core.MFString;
import com.thinkwide.data.debug.MFDebug;

import java.util.ArrayList;


public class MFServletMappingItems extends ArrayList<MFServletMappingItem> {


    private static final long serialVersionUID = 1L;

    public MFServletMappingItem find(String servletName) {
        for (MFServletMappingItem item : this) {
            if (MFString.compareCase(servletName, item.getServletName())) {
                MFDebug.println("find");
                return item;
            }

        }
        return null;
    }

    public String CheckPath(String url) {
        if (MFString.notNullOrEmpty(url) && !url.startsWith(MFPath.useparator))
            url = MFPath.useparator + url;
        return url;
    }

    public MFServletMappingItem findUrl(String url) {
        for (MFServletMappingItem item : this) {
            String Str = item.getUrlPattern();
            Str = CheckPath(Str);

            if (MFString.compareNoCase(url, Str)) {
                MFDebug.println("find:" + url);
                return item;
            }
        }

        return null;
    }
}

